package DesignModeTest;

/**
 * 装饰者模式
 */
public class TestDecorator {

  public static void main(String[] args) {
    Shape circle = new Circle();
    ShapeDecorator redCircle = new RedShapeDecorator(new Circle());
    ShapeDecorator redRectangle = new RedShapeDecorator(new Rectangle());

    circle.draw();

    redCircle.draw();

    redRectangle.draw();
  }
}

interface Shape{
  void draw();
}

class Rectangle implements Shape{

  @Override
  public void draw() {
    System.out.println("Shape: Rectangle");
  }
}

class Circle implements Shape{

  @Override
  public void draw() {
    System.out.println("Shape: Circle");
  }
}

abstract class ShapeDecorator implements Shape {
  protected Shape decoratorShape;

  public ShapeDecorator(Shape decoratorShape) {
    this.decoratorShape = decoratorShape;
  }

  @Override
  public void draw() {
    decoratorShape.draw();
  }
}

class RedShapeDecorator extends ShapeDecorator {

  public RedShapeDecorator(Shape decoratorShape) {
    super(decoratorShape);
  }

  @Override
  public void draw() {
    decoratorShape.draw();
    setRedShapeDecorator(decoratorShape);
  }

  private void setRedShapeDecorator(Shape decoratorShape) {
    System.out.println("Border Color : Red");
  }
}